package cn.stronglink.oil.widget;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.v7.widget.AppCompatTextView;
import android.util.AttributeSet;
import android.util.TypedValue;

/**
 * Created by chen on 2017/10/28.
 */

public class ElideTextView extends AppCompatTextView {
    private Context context;

    public ElideTextView(Context context) {
        super(context);
        this.context = context;
    }

    public ElideTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
    }


    public ElideTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        this.context = context;
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        Paint paint = new Paint();
        paint.setColor(Color.parseColor("#373C42"));
        paint.setStrokeWidth(dip2px(context, 0.8f));
        canvas.drawLine(0, dip2px(context, 0),getMeasuredWidth(), getMeasuredHeight(), paint);
    }

    private int dip2px(Context context,float dipValue)
    {
        Resources r = context.getResources();
        return (int) TypedValue.applyDimension(
                TypedValue.COMPLEX_UNIT_DIP, dipValue, r.getDisplayMetrics());
    }
}
